/*
 * BPlusTreeDefinitions.h
 *
 *  Created on: Nov 1, 2012
 *      Author: m
 */

#ifndef BPLUSTREEDEFINITIONS_H_
#define BPLUSTREEDEFINITIONS_H_

#include "../bplusnodes/NewLeaf.h"
#include "../bplusnodes/NewInternal.h"

// Definiciones para Arbol con registros de términos de diccionario ( DTR : Dictionary Term Record ).

/**
 * Esta estructura representa los datos guardados en el árbol
 *
 * En cada "Registro" el ábol tendrá una key y estos datos
 */

typedef unsigned int InvertedListPosition;

struct __attribute__ ((__packed__)) DictionaryTermAttributes
{
    size_t 					m_termPosition;
    InvertedListPosition 	m_invertedListPosition;
};

typedef std::string DTRkey_t;
typedef DictionaryTermAttributes DTRvalue_t;

extern DTRkey_t cropKey_func(const DTRkey_t& key, const DTRkey_t& prevKey);
extern bool keyComparator_func (const DTRkey_t& key1, const DTRkey_t& key2);

typedef NewNode     <DTRkey_t, DTRvalue_t, keyComparator_func>    Node;
typedef NewLeaf     <DTRkey_t, DTRvalue_t, keyComparator_func>    Leaf;
typedef NewInternal <DTRkey_t, DTRvalue_t, keyComparator_func>    Internal;

typedef std::shared_ptr< Node > node_ptr;

typedef typename Node::NodeOrder    NodeOrder_t;
typedef typename Node::NodeLevel    NodeLevel_t;
typedef typename Node::NodeID       NodeID_t;
typedef typename Node::searchResult searchResult_t;

typedef typename Leaf::registerType         	LeafRegister_t;
typedef typename Leaf::register_ptr         	LeafRegister_ptr;
typedef typename Leaf::registerPointerList  	LeafRegisterList_t;
typedef typename Leaf::registerPointerList_ptr	LeafRegisterList_ptr;

extern bool isOverflowLeaf_func (const LeafRegisterList_t& list);
extern bool isUnderflowLeaf_func(const LeafRegisterList_t& list);

typedef typename Leaf::SerializationBlock  LeafSerializationBlock;

typedef typename Internal::InternalRegisterType     		InternalRegister_t;
typedef typename Internal::InternalRegister_ptr     		InternalRegister_ptr;
typedef typename Internal::InternalRegisterPointerList  	InternalRegisterList_t;
typedef typename Internal::InternalRegisterPointerList_ptr	InternalRegisterList_ptr;

extern bool isOverflowInternal_func (const InternalRegisterList_t& list);
extern bool isUnderflowInternal_func(const InternalRegisterList_t& list);

typedef typename Internal::SerializationBlock  InternalSerializationBlock;

extern size_t getLeafNodeSize( const Leaf* );
extern size_t getInternalNodeSize( const Internal* );

#endif /* BPLUSTREEDEFINITIONS_H_ */
